<template>
  <div>
    <div class="wxcode">
      <div class="gongzhonghao" style="display: inline-block; float: left">
        <div style="float: left">
          <div style="height: 20px; line-height: 20px; text-align: center">普冷国际公众号</div>
          <img style="height: 80px" src="http://eim.kejicloud.com/images/plGZH.jpg" />
        </div>
        <div style="float: left; margin-left: 10px">
          <div style="height: 20px; rline-height: 20px; text-align: center">普冷库购公众号</div>
          <img style="height: 80px" src="http://eim.kejicloud.com/images/kugou.jpg" />
        </div>
      </div>
    </div>
    <j-modal
      :title="title"
      :width="width"
      :visible="visible"
      :mask="false"
      :keyboard="false"
      :closable="false"
      :maskClosable="false"
      :confirmLoading="confirmLoading"
      @ok="handleOk"
      @cancel="handleCancel"
      :ok-button-props="{ props: { disabled: disableSubmit } }"
      cancelText="关闭"
    >
      <template slot="footer">
        <a-button v-if="!disableSubmit" type="primary" @click="handleOk" :loading="buttonok">提交</a-button>
      </template>
      <a-spin :spinning="confirmLoading">
        <a-form :form="form">
          <a-row>
            <a-col :span="12">
              <a-form-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="['name', validatorRules.name]" placeholder="请输入姓名"></a-input>
              </a-form-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :span="12">
              <a-form-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <j-dict-select-tag
                  type="list"
                  v-decorator="['gender', validatorRules.gender]"
                  :trigger-change="true"
                  dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId =USER_SEX"
                  placeholder="请选择性别"
                />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="年龄" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="['age', validatorRules.age]" placeholder="请输入年龄"></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="婚姻状况" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <j-dict-select-tag
                  type="list"
                  v-decorator="['wedlock', validatorRules.wedlock]"
                  :trigger-change="true"
                  dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId =EMP_MARITAL_STATUS"
                  placeholder="请选择婚姻状况"
                />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="籍贯" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="['nativePlace']" placeholder="请输入籍贯"></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="邮箱" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="['email', validatorRules.email]" placeholder="请输入邮箱"></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="手机" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="['phone', validatorRules.phone]" placeholder="请输入手机"></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="学历" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <j-dict-select-tag
                  @change="selectChange"
                  type="list"
                  v-decorator="['education', validatorRules.education]"
                  :trigger-change="true"
                  dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId = EMP_EDUCATION"
                  placeholder="请选择学历"
                />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="本科毕业院校" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="['school', validatorRules.school]" placeholder="请输入毕业院校"></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="本科所学专业" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="['specialty', validatorRules.specialty]" placeholder="请输入所学专业"></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="12" v-if="education">
              <a-form-item label="研究生毕业院校" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input
                  v-decorator="['masterSchool', validatorRules.masterSchool]"
                  placeholder="请输入研究生毕业院校"
                ></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="12" v-if="education">
              <a-form-item label="研究生所学专业" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input
                  v-decorator="['masterSpecialty', validatorRules.masterSpecialty]"
                  placeholder="请输入研究生所学专业"
                ></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="应聘职位" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="['position', validatorRules.position]" placeholder="请输入应聘职位"></a-input>
                <!-- <j-dict-select-tag  type="list" v-decorator="['position', validatorRules.position]" :trigger-change="true" dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId =POSITION" placeholder="请选择应聘职位"/> -->
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="期望年薪(元)" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input
                  v-decorator="['expectedSalaryMin', validatorRules.expectedSalaryMin]"
                  style="width: 42.5%; text-align: center"
                  placeholder="最低年薪"
                ></a-input>
                <a-input
                  style="width: 15%; border: 0; pointer-events: none; background-color: #fff; text-align: center"
                  value="~"
                  disabled
                />
                <a-input
                  v-decorator="['expectedSalaryMax', validatorRules.expectedSalaryMax]"
                  style="width: 42.5%; text-align: center"
                  placeholder="最高年薪"
                ></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="来源" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <j-dict-select-tag
                  type="list"
                  v-decorator="['source', validatorRules.source]"
                  :trigger-change="true"
                  dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId =CANDIDATE_SOURSE"
                  placeholder="请选择来源"
                />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="意向工作地" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input
                  v-decorator="['intentionWork', validatorRules.intentionWork]"
                  placeholder="请输入意向工作地"
                ></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="上岗时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <!-- <j-date  placeholder="请选择上岗时间" v-decorator="['startDate', validatorRules.startDate]" :trigger-change="true" style="width: 100%"/> -->
                <j-dict-select-tag
                  type="list"
                  v-decorator="['startDate', validatorRules.startDate]"
                  :trigger-change="true"
                  dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId =START_DATE"
                  placeholder="请选择上岗时间"
                />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="简历上传" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <j-upload
                  :disabled="disableSubmit"
                  fileType="pdf"
                  :isMultiple="false"
                  v-decorator="['uploadPath', validatorRules.uploadPath]"
                  :trigger-change="true"
                ></j-upload>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </a-spin>
    </j-modal>

    <a-result
      v-if="!visible"
      style="backgroundcolor: #fff; border-radius: 10px; opacity: 0.8"
      status="success"
      title="提交职员信息成功！"
    >
    </a-result>
  </div>
</template>

<script>
import { httpAction } from '@/api/manage'
import pick from 'lodash.pick'
import { validateDuplicateValue } from '@/utils/util'
import JDate from '@/components/jeecg/JDate'
import JDictSelectTag from '@/components/dict/JDictSelectTag'
import JSearchSelectTag from '@/components/dict/JSearchSelectTag'
import JUpload from '@/components/jeecg/JUpload'
export default {
  name: 'HrCandidateInfoModal',
  components: {
    JUpload,
    JDate,
    JDictSelectTag,
    JSearchSelectTag,
  },
  data() {
    return {
      form: this.$form.createForm(this),
      title: '普冷国际应聘者信息',
      width: 1000,
      visible: true,
      buttonok: false,
      education: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 8 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      disableSubmit: false,
      confirmLoading: false,
      validatorRules: {
        name: {
          rules: [{ required: true, message: '请输入姓名!' }],
        },
        gender: {
          rules: [{ required: true, message: '请输入性别!' }],
        },
        age: {
          rules: [
            { required: true, message: '请输入年龄!' },
            { pattern: /^-?\d+$/, message: '请输入整数!' },
          ],
        },
        wedlock: {
          rules: [{ required: true, message: '请输入婚姻状况!' }],
        },
        email: {
          rules: [{ required: true, message: '请输入邮箱!' }],
        },
        phone: {
          rules: [{ required: true, message: '请输入手机!' }],
        },
        specialty: {
          rules: [{ required: true, message: '请输入本科所学专业!' }],
        },
        school: {
          rules: [{ required: true, message: '请输入本科毕业院校!' }],
        },
        education: {
          rules: [{ required: true, message: '请输入学历!' }],
        },
        position: {
          rules: [{ required: true, message: '请输入应聘职位!' }],
        },
        expectedSalary: {
          rules: [{ required: true, message: '请输入期望年薪!' }],
        },
        expectedSalaryMin: {
          rules: [{ required: true, message: '请输入期望最低年薪!' }],
        },
        expectedSalaryMax: {
          rules: [{ required: true, message: '请输入期望最高年薪!' }],
        },
        source: {
          rules: [{ required: true, message: '请选择来源!' }],
        },
        intentionWork: {
          rules: [{ required: true, message: '请输入意向工作地!' }],
        },
        writeDate: {
          rules: [{ required: true, message: '请输入填表日期!' }],
        },
        startDate: {
          rules: [{ required: true, message: '请选择上岗时间!' }],
        },
        uploadPath: {
          rules: [{ required: true, message: '请上传简历!' }],
        },
        masterSchool: {
          rules: [{ required: true, message: '请输入研究生毕业院校!' }],
        },
        masterSpecialty: {
          rules: [{ required: true, message: '请输入研究生所学专业!' }],
        },
      },
      url: {
        save: '/online/saveHrCandidateInfo',
        get: '/online/getHrCandidateInfoJson',
      },
    }
  },
  created() {
    let id = this.$route.query.id
    this.init(id)
  },
  methods: {
    init(id) {
      this.form.resetFields()
      this.visible = true
      this.model = {}
      if (id) {
        httpAction(this.url.get, { id: id }, 'post').then((res) => {
          this.model = Object.assign({}, res.nfs)
          this.$nextTick(() => {
            this.form.setFieldsValue(
              pick(
                this.model,
                'name',
                'gender',
                'age',
                'birthday',
                'wedlock',
                'nationId',
                'nativePlace',
                'politicId',
                'email',
                'phone',
                'address',
                'specialty',
                'school',
                'education',
                'workExperience',
                'trainingAttend',
                'awardPunish',
                'position',
                'expectedSalary',
                'expectedSalaryMin',
                'expectedSalaryMax',
                'source',
                'intentionWork',
                'writeDate',
                'startDate',
                'otherRequirements',
                'uploadPath',
                'masterSchool',
                'masterSpecialty'
              )
            )
          })
        })
      }
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true
          that.buttonok = true
          let httpurl = this.url.save
          let method = 'post'
          let formData = Object.assign(this.model, values)
          console.log('表单提交数据', formData)
          httpAction(httpurl, formData, method)
            .then((res) => {
              that.$message.success('提交成功！')
              that.$emit('ok')
              setTimeout(() => {
                that.buttonok = false
              }, 500)
            })
            .finally(() => {
              that.confirmLoading = false
              that.close()
            })
        }
      })
    },
    handleCancel() {
      this.close()
    },
    popupCallback(row) {
      this.form.setFieldsValue(
        pick(
          row,
          'name',
          'gender',
          'age',
          'birthday',
          'wedlock',
          'nationId',
          'nativePlace',
          'politicId',
          'email',
          'phone',
          'address',
          'specialty',
          'school',
          'education',
          'workExperience',
          'trainingAttend',
          'awardPunish',
          'position',
          'expectedSalary',
          'expectedSalaryMin',
          'expectedSalaryMax',
          'source',
          'intentionWork',
          'writeDate',
          'startDate',
          'otherRequirements',
          'uploadPath',
          'masterSchool',
          'masterSpecialty'
        )
      )
    },
    selectChange(e) {
      let number = parseInt(e)
      if (number > 6) {
        this.education = true
      } else {
        this.education = false
      }
    },
  },
}
</script>
<style lang="less" scoped>
.wxcode {
  position: fixed;
  top: 20px;
  left: 20px;
}
</style>